package com.young.fragments.demo.simple_jump_demo.fms

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.young.fragments.databinding.FmSimpleJumpTargetBinding
import com.young.lib_fragments.fms.BaseLazyFragment

/**
 * @author huangzehui
 * @date 2025/1/12 22:14 周日
 * @description 简单跳转的目标fragment
 */
class SimpleJumpTargetFragment : BaseLazyFragment(), View.OnClickListener {

    private lateinit var mBinding: FmSimpleJumpTargetBinding

    companion object {
        // 回退栈信息的名称
        val BACK_STACK_NAME = "second"
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = FmSimpleJumpTargetBinding.inflate(inflater, container, false)
        return mBinding.root
    }


    @SuppressLint("SetTextI18n")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        val backStackEntryCount = parentFragmentManager.backStackEntryCount
        if (backStackEntryCount > 0) {
            mBinding.tvText.text = "fmTag=${BACK_STACK_NAME} \nid=${
                parentFragmentManager.getBackStackEntryAt(backStackEntryCount - 1).id
            }"
        } else {
            mBinding.tvText.text = "fmTag=${BACK_STACK_NAME} id=未知"
        }



        mBinding.btnJumpTarget.setOnClickListener(this)
        mBinding.btnLast.setOnClickListener(this)

    }

    override fun onClick(v: View?) {
        when (v) {
            mBinding.btnJumpTarget -> {
                start(fm = SimpleJumpTargetFragment1(), toBackStackName = SimpleJumpTargetFragment1.BACK_STACK_NAME)
            }

            mBinding.btnLast -> {
//                FmTransitionsUtil.pop(parentFragmentManager)
                pop()
            }
        }
    }

}